package cn.iocoder.ny.module.activity.controller.admin.tpActivity;

/**
 * @author luchunhong
 * @date 2024/11/24/ 13:41
 * @description:
 */

import cn.iocoder.ny.module.activity.controller.admin.tpActivity.vo.TpActivityPageReqVo;
import cn.iocoder.ny.module.activity.controller.admin.tpActivity.vo.TpActivityRespVo;
import cn.iocoder.ny.module.activity.controller.admin.tpActivity.vo.TpActivityVo;
import cn.iocoder.ny.module.activity.domain.TpActivity;
import cn.iocoder.ny.module.activity.service.ITpActivityService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.dal.dataobject.activity.ActivityUser;
import cn.iocoder.yudao.module.system.service.activity.ActivityService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import java.util.List;

import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;

/**
 * 投票活动管理
 */
@RequestMapping("tp-activity")
@RestController
public class TpActivityController {
    @Resource
    private ITpActivityService tpActivityService;
    @Resource
    private ActivityService activityService;

    /**
     * 投票活动新增
     */
    @PostMapping("addTpActivity")
    public CommonResult addTpActivity(@RequestBody TpActivityVo tpActivityVo){
        //  投票活动新增
        tpActivityService.addTpActivity(tpActivityVo);
        return CommonResult.success(true);
    }
    /**
     * 查询当前账号下的投票活动列表(分页)
     */
    @PostMapping("list")
//    @PreAuthorize("@ss.hasAnyRoles('tp_common','super_admin')")
    public CommonResult<PageResult<TpActivityRespVo>> list(@RequestBody TpActivityPageReqVo tpActivityPageReqVo){
        PageResult<TpActivityRespVo> tpActivityRespVoPageResult = tpActivityService.queryPageList(tpActivityPageReqVo);
        System.err.println(tpActivityRespVoPageResult);
        return CommonResult.success(tpActivityRespVoPageResult);
    }
    /**
     * 根据活动ID查询投票活动信息
     */
    @PostMapping("queryByActivityId")
    public CommonResult queryByActivityId(@RequestBody TpActivityVo tpActivityVo){
        TpActivityRespVo tpActivityRespVo = tpActivityService.queryByActivityId(tpActivityVo);
        return CommonResult.success(tpActivityRespVo);
    }
    /**
     * 生成投票活动二维码
     */
    @PostMapping("createActivityQrCode")
    public CommonResult createActivityQrCode(@RequestBody TpActivityVo tpActivityVo){
        String activityQrCode = tpActivityService.createActivityQrCode(tpActivityVo);
        return CommonResult.success(activityQrCode);
    }
    /**
     * 生成投票首页员工绑定二维码
     */
    @PostMapping("createAdminActivityQrCode")
    public CommonResult createAdminActivityQrCode(@RequestBody TpActivityVo tpActivityVo){
        String activityQrCode = tpActivityService.createAdminActivityQrCode(tpActivityVo);
        return CommonResult.success(activityQrCode);
    }
    /**
     * 修改投票活动
     */
    @PostMapping("updateTpActivity")
    public CommonResult updateTpActivity(@RequestBody TpActivity tpActivity){
        //  修改活动
        Boolean activity = null;
        try {
            activity = tpActivityService.updateTpActivity(tpActivity);
        } catch (RuntimeException e) {
            return CommonResult.error(500,e.getMessage());
        }
        if (activity){
            return CommonResult.success(true);
        }
        return null;
    }
}
